<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<<<<<<< HEAD
      <el-form-item label="商品名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入商品名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
         <el-form-item label="商品价格" >
          <el-input
            type="number"
            v-model="queryParams.params.minPrice"
            size="small"
            style="width: 120px"
            @keyup.native="reload"
          ></el-input>
          <span>——</span>
          <el-input
            type="number"
            v-model="queryParams.params.maxPrice"
            size="small"
            style="width: 120px"
            @keyup.native="reload"
          ></el-input>
        </el-form-item>
      <el-form-item label="销售时间">
          <el-date-picker
            v-model="dateRange"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
          <el-form-item label="商品类型" prop="type">
                <el-select v-model="queryParams.type" placeholder="商品类型"  clearable  size="small"  style="width: 240px">
                  <el-option
                    v-for="dict in dict.type.sys_myNote_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
          <el-form-item label="类型" prop="trade">
          <el-select
            v-model="queryParams.trade"
            placeholder="交易类型"
            clearable
            size="small"
            style="width: 240px"
          >
          <el-option label="买进" value="0"></el-option>
          <el-option label="卖出" value="1"></el-option>
            <!-- <el-option
              v-for="dict in dict.type.sys_common_trade"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            /> -->
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon- " size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
=======
     <el-form-item label="操作时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['my:myNote:remove']"
        >删除</el-button>
      </el-col>
<<<<<<< HEAD
=======
      <!-- <el-col :span="1.5">
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
<<<<<<< HEAD
        >导出</el-button>
=======
          v-hasPermi="['my:myNote:export']"
        >导出</el-button>
      </el-col> -->
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="记事ID" align="center" prop="myNoteId" /> -->
<<<<<<< HEAD
      <el-table-column label="商品名称" align="center" prop="name" :show-overflow-tooltip="true" />
      <el-table-column label="商品类型" align="center" prop="type" width="100">
       <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_myNote_type" :value="scope.row.type" />
        </template>
        </el-table-column>
      <el-table-column label="商品价格" align="center" prop="price" />
      <el-table-column label="交易类型" align="center" prop="trade" :formatter="woPassFormat" />
      <el-table-column label="创建时间" align="center" prop="sale_time" width="180">
=======
      <el-table-column label="商品名称" align="center" prop="name" />
      <el-table-column label="商品价格" align="center" prop="price" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
        </template>
      </el-table-column>
<<<<<<< HEAD
      <el-table-column label="销售时间" align="center" prop="saleTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.saleTime, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
        </template>
      </el-table-column>
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
         
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
        
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改记事本对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<<<<<<< HEAD
      <el-row>
      <el-col :span="12">
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入商品名称" />
        </el-form-item>
        </el-col>
         <el-col :span="12">
            <el-form-item label="交易类型" prop="trade">
              <el-select v-model="form.trade" placeholder="请选择">
               <el-option label="买进" value="0"></el-option>
                 <el-option label="卖出" value="1"></el-option>
                <!-- <el-option
                  v-for="dict in dict.type.sys_common_trade""
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option> -->
              </el-select>
            </el-form-item>
          </el-col>
          </el-row>
        <el-form-item label="照片" prop="pics">
           <image-upload v-model="form.pics" :limit="2"/>
        </el-form-item>
      <el-form-item label="销售时间">
         <el-date-picker
      v-model="form.saleTime"
      type="datetime"
      placeholder="选择日期时间"
      format="yyyy-MM-dd HH:mm:ss"
      value-format="yyyy-MM-dd HH:mm:ss">
    </el-date-picker>
        </el-date-picker>
      </el-form-item>
            <el-form-item label="商品类型">
              <el-select v-model="form.type" placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.sys_myNote_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input type="number" @keydown="handleInput2" v-model="form.price" placeholder="请输入商品价格" />
=======
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="照片" prop="pics">
           <image-upload v-model="form.pics" :limit="2"/>
        </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入商品价格" />
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
<<<<<<< HEAD
=======
       
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMyNote, getMyNote, delMyNote, addMyNote, updateMyNote, exportMyNote } from "@/api/my/myNote";

export default {
<<<<<<< HEAD
  name: "MyNote",
  dicts: ['sys_common_trade','sys_myNote_type'],
=======
  //name: "MyNote",
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
<<<<<<< HEAD
      single: true, 
=======
      single: true,
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //表格数据
      list:[],
      // 记事本表格数据
      myNoteList: [],
      //日期范围
      dateRange: [],
<<<<<<< HEAD
       //日期范围
      priceRange: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 商品价格字典
      priceOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
<<<<<<< HEAD
        price: null, 
        minPrice: null,
        maxPrice: null,
        trade: null, 
        type: null,
=======
        price: null,  
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "商品名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    debugger;
<<<<<<< HEAD
     const trade = this.$route.params && this.$route.params.trade;
     this.queryParams.trade = trade;
      const type = this.$route.params && this.$route.params.type;
      this.queryParams.type = type;
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
    this.getList();
    this.getDicts("sys_notice_status").then(response => {
      this.priceOptions = response.data;
    });
  },
<<<<<<< HEAD
  methods: { 
    /** 查询记事本列表 */
    getList() {
      this.loading = true;
      debugger;
      let var1 = this.addDateRange(this.queryParams,this.dateRange);
     // let var2 = this.addDateRange(var1,this.priceRange);
      listMyNote(var1).then( response => {
=======
  methods: {
    /** 查询记事本列表 */
    getList() {
      this.loading = true;
      listMyNote(this.addDateRange(this.queryParams,this.dateRange)).then( response => {
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
<<<<<<< HEAD
    handleInput2(e) {
            // 通过正则过滤小数点后两位
            e.target.value = (e.target.value.match(/^\d*(\.?\d{0,1})/g)[0]) || null
        },

      //监听商品价格刷新
    reload() {
       debugger;
        this.$forceUpdate()
      },
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
    // 商品价格字典翻译
    priceFormat(row, column) {
      return this.selectDictLabel(this.priceOptions, row.price);
    },
<<<<<<< HEAD
    // 商品类型字典翻译
    woPassFormat(row, column) {
      if(row.trade==1)
      return '卖出';
      else
      {
        return '买进'
      }
    },
    // 取消按钮
      cancel() {
=======
    // 取消按钮
    cancel() {
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        myNoteId: null,
        projectId: null,
        name: null,
<<<<<<< HEAD
        trade: null,
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
        pics: null,
        price: null,
        remark: null,
        delFlag: null,
<<<<<<< HEAD
=======
        status: "0",
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
<<<<<<< HEAD
      this.queryParams = [];
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.myNoteId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加记事本";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const myNoteId = row.myNoteId || this.ids
      getMyNote(myNoteId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改记事本";
      });
    },
    /** 提交按钮 */
    submitForm() {
<<<<<<< HEAD
      debugger;
      this.form.price = Number(this.form.price);
=======
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.myNoteId != null) {
            updateMyNote(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMyNote(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const myNoteIds = row.myNoteId || this.ids;
      this.$confirm('是否确认删除记事本编号为"' + myNoteIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMyNote(myNoteIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
<<<<<<< HEAD
      this.download('my/myNote/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
     /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('my/myNote/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
=======
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有记事本数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportMyNote(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
>>>>>>> 260ca11a12a6e353375de1bfd8f7264a63d0cf7a
    }
  }
};
</script>
